﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class InteractivePlatform : System.Web.UI.Page
{
	private PX.Config clsConfig = new PX.Config();
	private PX.Expert.ExpertComponent clsExpertComp = new PX.Expert.ExpertComponent();
	

	protected override void OnInit(EventArgs e)
	{
		lBtnExpertOne.Text = clsConfig.strArrExpert[clsConfig.nExpert_One].ToString();
		lBtnExpertTwo.Text = clsConfig.strArrExpert[clsConfig.nExpert_Two].ToString();

		lBtnExpertOne.Click += new EventHandler(lBtnExpertOne_Click);
		lBtnExpertTwo.Click += new EventHandler(lBtnExpertTwo_Click);
		radioExpert.SelectedIndexChanged += new EventHandler(radioExpert_SelectedIndexChanged);
		lBtnAdd.Click += new EventHandler(lBtnAdd_Click);
		base.OnInit(e);
	}

	void lBtnAdd_Click(object sender, EventArgs e)
	{
		PX.ExpertQA.ExpertQA clsAdd = new PX.ExpertQA.ExpertQA();
		PX.ExpertQA.ExpertQAComponent clsExpertQAComp = new PX.ExpertQA.ExpertQAComponent();

		PX.Expert.Expert clsExpert = new PX.Expert.Expert();

		clsExpert = (PX.Expert.Expert)clsExpertComp.GetOneByID(Convert.ToInt32(radioExpert.SelectedValue));

		clsAdd.ExpertID = clsExpert.UserID;
		clsAdd.QDateTime = System.DateTime.Now.ToString();
		clsAdd.Question = txtQuestion.Text;
		clsAdd.WhetherAnswer = clsConfig.nNoAnswer;
		clsAdd.ExpertType = clsExpert.Type;

		clsExpertQAComp.Add(clsAdd);
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			QueryExpert(clsConfig.nExpert_One);

			imgExpert.Visible = false;
		}

	}

	void radioExpert_SelectedIndexChanged(object sender, EventArgs e)
	{
		int nExpertID = 0;
		PX.Expert.Expert clsExpert = new PX.Expert.Expert();

		imgExpert.Visible = true;

		nExpertID = Convert.ToInt32(radioExpert.SelectedValue);

		clsExpert = (PX.Expert.Expert)clsExpertComp.GetOneByID(nExpertID);

		imgExpert.ImageUrl = "~/ShowImage.aspx?FileID=" + clsExpert.ImageID.ToString();

		litIntroduction.Text = "<iframe class = 'expertIntroduction' src = '../ShowImageFile.aspx?FileID=" + clsExpert.IntroductionID + "'></iframe>";
	}

	void lBtnExpertTwo_Click(object sender, EventArgs e)
	{
		QueryExpert(clsConfig.nExpert_Two);
	}

	void lBtnExpertOne_Click(object sender, EventArgs e)
	{
		QueryExpert(clsConfig.nExpert_One);
	}

	private void QueryExpert(int nExpertType)
	{
		List<Tony.EntityBase> listExpert = new List<Tony.EntityBase>();
		int i = 0;
		PX.Expert.Expert clsExpert = new PX.Expert.Expert();

		listExpert = clsExpertComp.Query(nExpertType);

		radioExpert.Items.Clear();
		i = 0;
		while (i < listExpert.Count)
		{
			clsExpert = (PX.Expert.Expert)listExpert[i];
			radioExpert.Items.Add(new ListItem(clsExpert.Name, clsExpert.ID.ToString()));
			i = i + 1;
		}
	}
}
